package net.huashitong.ssydt.provider.exam.service;


import net.huashitong.ssydt.exam.entity.SsExamErrorQuestion;
import net.huashitong.ssydt.exam.entity.vo.ErrorRecordsInVO;
import net.huashitong.ssydt.exam.entity.vo.QuestionErrorCollectionListInVO;
import net.huashitong.ssydt.exam.entity.vo.QuestionErrorListOutVO;
import net.huashitong.ssydt.provider.exam.mapper.SsExamErrorQuestionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2017.09.06
 */
@Service
@Transactional
public class SsExamErrorQuestionServiceImpl implements SsExamErrorQuestionService {

    private SsExamErrorQuestionMapper mapper;

    @Autowired
    public SsExamErrorQuestionServiceImpl(SsExamErrorQuestionMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(SsExamErrorQuestion record) {
        return mapper.insert(record);
    }

    @Override
    public int insertSelective(SsExamErrorQuestion record) {
        return mapper.insertSelective(record);
    }

    @Override
    public SsExamErrorQuestion selectByPrimaryKey(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(SsExamErrorQuestion record) {
        return mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(SsExamErrorQuestion record) {
        return mapper.updateByPrimaryKey(record);
    }

    @Override
    public SsExamErrorQuestion getByUserIdWithQuestionId(String userId, Long questionId) {
        SsExamErrorQuestion ssExamErrorQuestion = new SsExamErrorQuestion();
        ssExamErrorQuestion.setUserId(userId);
        ssExamErrorQuestion.setQuestionId(questionId);
        return mapper.getByUserIdWithQuestionId(ssExamErrorQuestion);
    }

    @Override
    public List<QuestionErrorListOutVO> countGroupByBelongYearMonthByUserId(QuestionErrorCollectionListInVO questionErrorCollectionListInVO) {
        return mapper.countGroupByBelongYearMonthByUserId(questionErrorCollectionListInVO);
    }

    @Override
    public List<SsExamErrorQuestion> findByUserIdWithBelongYearMonth(String userId, String belongYearMonth) {
        SsExamErrorQuestion ssExamErrorQuestion = new SsExamErrorQuestion();
        ssExamErrorQuestion.setUserId(userId);
        ssExamErrorQuestion.setBelongYearMonth(belongYearMonth);
        return mapper.findByUserIdWithBelongYearMonth(ssExamErrorQuestion);
    }

    @Override
    public int countLessTanErrorQuestionId(String belongYearMonth, ErrorRecordsInVO errorRecordsInVO) {
        SsExamErrorQuestion ssExamErrorQuestion = new SsExamErrorQuestion();
        ssExamErrorQuestion.setUserId(errorRecordsInVO.getUserId());
        ssExamErrorQuestion.setBelongYearMonth(belongYearMonth);
        ssExamErrorQuestion.setId(errorRecordsInVO.getErrorQuestionId());
        return mapper.countLessTanErrorQuestionId(ssExamErrorQuestion);
    }

    @Override
    public int deleteByUserId(String userId) {
        return mapper.deleteByUserId(userId);
    }

    @Override
    public int countUserIdWithBelongYearMonth(String userId, String belongYearMonth) {
        SsExamErrorQuestion ssExamErrorQuestion = new SsExamErrorQuestion();
        ssExamErrorQuestion.setUserId(userId);
        ssExamErrorQuestion.setBelongYearMonth(belongYearMonth);
        return mapper.countUserIdWithBelongYearMonth(ssExamErrorQuestion);
    }
}
